<template>
  <div>
    <div class="TopClass" @mouseover="handleMouseoverTopClass" @mouseout="handleMouseleaveTopClass">
      <div class="Top-logo">
        <img src="../../../../assets/icons/svg/wg.svg">
      </div>
      <div class="Top-Center">
        <div v-for="(item,index) in MeanList"
             class="meanClass"
             :key="index"
             @mouseover="handleMouseover(item,index)"
             @mouseout="handleMouseleave()">
          <div class="meanTextClass">
            {{ item.label }}
          </div>
          <div class="BorderLeft"></div>
        </div>
      </div>
      <div class="Top-Right">
      </div>
    </div>
    <transition>
    <div class="BottonmClass" v-show="isOpenBottom" @mouseover="handleMouseoverBottomClass"
         @mouseout="handleMouseleaveBottomClass">
      <div class="BottonmClassCenter" v-for="(item,index) in BottomList" :key="index"
           @mouseover="handleMouseoverBottomClassText(item,index)" @mouseout="handleMouseleaveBottomClassText">
        <div class="BottonmClassCenterText">
          <div>
            {{ item.label }}
          </div>
          <div><img :src="item.img"></div>
        </div>
        <div class="BorderLeft"></div>
      </div>

    </div>
    </transition>
  </div>
</template>

<script setup>
import {computed, onMounted, ref, toRefs} from "vue";
import menuJthSvg from '@/assets/WeGao/svg/menu_jth.svg'; // 根据你的项目目录结构进行调整
import menuJthLightSvg from '@/assets/WeGao/svg/menu_jth_light.svg'; // 根据你的项目目录结构进行调整

const emit = defineEmits()
defineOptions({name: "TopWeiGao"})
const props = defineProps({
  // 背景色
  TopClassbg: {
    type: String,
  }
})
const {TopClassbg} = toRefs(props)
// 页面背景色
const computedBgColor = ref(props.TopClassbg)

const BottomList = ref([])
const isOpenBottom = ref(true)
const imageUrlBottom = ref(menuJthSvg)

const colorClass = ref('rgba(255,255,255)')
// top的菜单栏
const MeanList = ref([
  {value: '0', label: "首页"},
  {
    value: '0',
    label: "关于威高",
    children: [{
      value: '0',
      label: "威高简介",
      img: menuJthSvg,
    }, {
      value: '1',
      label: "企业文化",
      img: menuJthSvg,
    }, {
      value: '2',
      label: "发展历程",
      img: menuJthSvg,
    },]
  },
  {
    value: '0', label: "产品中心",
    children: [{
      value: '0',
      label: "通用耗材",
      img: menuJthSvg,
    }, {
      value: '1',
      label: "内分泌",
      img: menuJthSvg,
    }, {
      value: '2',
      label: "医疗信息化",
      img: menuJthSvg,
    }, {
      value: '3',
      label: "骨科",
      img: menuJthSvg,
    }, {
      value: '4',
      label: "口腔",
      img: menuJthSvg,
    }, {
      value: '5',
      label: "组织修复",
      img: menuJthSvg,
    }, {
      value: '6',
      label: "血液净化",
      img: menuJthSvg,
    }, {
      value: '7',
      label: "药材包",
      img: menuJthSvg,
    }, {
      value: '8',
      label: "外科",
      img: menuJthSvg,
    }, {
      value: '9',
      label: "手术机器人",
      img: menuJthSvg,
    }, {
      value: '10',
      label: "全血采集",
      img: menuJthSvg,
    }, {
      value: '11',
      label: "介入",
      img: menuJthSvg,
    }, {
      value: '12',
      label: "体外诊断",
      img: menuJthSvg,
    }, {
      value: '13',
      label: "辅助生殖",
      img: menuJthSvg,
    }, {
      value: '14',
      label: "医用医疗设备",
      img: menuJthSvg,
    }, {
      value: '15',
      label: "康复系列",
      img: menuJthSvg,
    }, {
      value: '16',
      label: "内窥镜",
      img: menuJthSvg,
    }, {
      value: '18',
      label: "药品",
      img: menuJthSvg,
    },
    ]
  },
  {
    value: '0',
    label: "新闻中心",
    children: [
      {
        value: '0', label: "公司新闻", img: menuJthSvg,
      }
    ]
  },
  {value: '0', label: "ESG"},
  {value: '0', label: "加入威高"},
  {value: '0', label: "集团成员"},
  {
    value: '0', label: "服务中心",
    children: [
      {
        value: '0',
        label: "服务中心",
        img: menuJthSvg,
      }, {
        value: '1',
        label: "供应商门户",
        img: menuJthSvg,
      },
    ]
  },

])


// 聚焦事件
function handleMouseoverTopClass() {

  // 背景色
  computedBgColor.value = "rgba(255,255,255)"
  // 字体颜色
  colorClass.value = "rgba(0,0,0)"

}

// 失焦事件
function handleMouseleaveTopClass(item, index) {
  // 背景色
  computedBgColor.value = "rgba(0,0,0,0)"
  // 字体颜色
  colorClass.value = "rgba(255,255,255)";
}

function handleMouseover(item, index) {
  if(MeanList.value[index].children){
    BottomList.value = MeanList.value[index].children
    // 聚焦展现子集
    isOpenBottom.value = MeanList.value[index]?.children.length !== 0;
  }


}

function handleMouseleave() {

  // 背景色
  computedBgColor.value = "rgba(0,0,0,0)"
  // 字体颜色
  colorClass.value = "rgba(255,255,255)"

  isOpenBottom.value = false
}

// 底部全面聚焦
function handleMouseoverBottomClass() {
  // 背景色
  computedBgColor.value = "rgba(255,255,255)"
  // 字体颜色
  colorClass.value = "rgba(0,0,0)"

  isOpenBottom.value = true


}


function handleMouseleaveBottomClass() {

  // 背景色
  computedBgColor.value = "rgba(0,0,0,0)"
  // 字体颜色
  colorClass.value = "rgba(255,255,255)";

  isOpenBottom.value = false


}

function handleMouseoverBottomClassText(item,index) {
  BottomList.value.forEach((it,index1)=>{
    if(it.value===item.value){
      BottomList.value[index1].img=menuJthLightSvg
    }else{
      BottomList.value[index1].img=menuJthSvg
    }
  })
}

function handleMouseleaveBottomClassText() {

}
</script>

<style scoped lang="scss">
.meanClass {
  --color: v-bind(colorClass);
  color: var(--color);
}

.meanTextClass {
  height: 99%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.meanTextClass:hover {
  height: 99%;
  color: rgba(13, 158, 215);
}

.meanClass:hover {
  .BorderLeft {
    height: 1%;
    animation: lineAppear 0.5s ease-in-out forwards;
  }
}

.BorderLeft {
  width: 100%;
  height: 1%;
}


.TopClass {
  --backgroundClor: v-bind(computedBgColor);
  background: var(--backgroundClor);
  border-bottom: 1px solid white;
  display: flex;
  align-items: center;
  width: 100%;
  height: 10vh;

  .Top-logo {
    margin-left: 3rem;
    width: 20%;
  }

  .Top-Center {
    width: 60%;
    display: flex;
    justify-content: space-around;
    height: 100%;
  }

  .Top-Right {
    width: 20%;
  }

}

.BottonmClass {
  border-top: 1px solid #666666;
  height: 100%;
  width: 100%;
  padding: 0 10% 2% 10%;
  --backgroundClor: v-bind(computedBgColor);
  background: var(--backgroundClor);

  display: flex;
  justify-content: left;
  flex-wrap: wrap;
}


.BottonmClassCenter {
  width: 16%;
}

.BottonmClassCenterText {
  text-align: left;
  height: 100%;
  width: 100%;
  padding: 10% 10% 10% 0;
  display: flex;
  justify-content: space-between;
}

.BottonmClassCenter:hover {
  .BorderLeft {
    height: 1%;
    animation: lineAppearBottom 0.5s ease-in-out forwards;
  }

}

@keyframes lineAppearBottom {
  0% {
    height: 2px;
    width: 0;
    background-color: rgba(13, 158, 215);
    border-radius: 5px;

  }
  100% {
    height: 2px;
    width: 90%;
    background-color: rgba(13, 158, 215);
    border-radius: 5%;
  }

}

@keyframes lineAppear {
  0% {
    height: 2px;
    width: 0;
    background-color: rgba(13, 158, 215);
    border-radius: 5px;

  }
  100% {
    height: 2px;
    width: 100%;
    background-color: rgba(13, 158, 215);
    border-radius: 5%;
  }

}



.v-enter-active {
  transition: all 0.5s ease-out;
}

.v-leave-active {
  transition: all 0.5s cubic-bezier(1, 0.5, 0.8, 1);
}

.v-enter-from,
.v-leave-to {
  transform: translateY(-1rem);
  opacity: 0;

}

</style>

